import request from '@/utils/request';
import { useTokenStore } from '@/stores/token';

export default {
    user: {
        list: (params) => request.post('/binlog/user/list',params),
        create: (userData) => request.post('/binlog/user/admin/create', userData),
        delete: (userId) => request.delete(`/binlog/user/${userId}`)
    },
    binlog: {
        list: (data, pageNum = 1, pageSize = 10) => {
            // 将分页参数合并到请求体中，而不是作为URL参数
            const requestData = {
                ...data,
                pageNum,
                pageSize
            };
            
            // 确保每次请求都使用最新的token
            const tokenStore = useTokenStore();
            const config = {
                headers: {
                    'Authorization': `Bearer ${tokenStore.token}`
                }
            };
            
            return request.post('/binlog/binlogAddress/list', requestData, config);
        },
        test:(params) => request.post('/binlog/binlogAddress/test', params),
        add: (params) => request.post('/binlog/binlogAddress/add', params),
        getDataBaseList: (params) => request.post('/binlog/binlogAddress/getDataBaseList', params),
        getDataTableList: (params) => request.post('/binlog/binlogAddress/getDataTableList', params),
        getHisSqlList: (params) => request.post('/binlog/binlogAddress/getHisSqlList', params),
        generateSql: (params) => request.post('/binlog/binlogAddress/generatedSqlList', { ...params}),
        delete: (params) => request.post('/binlog/binlogAddress/delete', params),
        updateByBinlogAddress: (params) => request.post('/binlog/binlogAddress/updateByBinlogAddress', params),
        getProgress: (params) => request.post('/binlog/binlogAddress/getProgress', params)
    },
    mybatis: {
        generator:(params) => request.post('/mybatisPlus/generator', params),
    }
    // 其他API端点...
};